package com.hsy.managemoney.modules.utils;

import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;

import com.hsy.managemoney.modules.common.Conts;
import com.hsy.managemoney.modules.view.LoadingDialog;

/**
 * Created by Administrator on 2016/10/31.
 */
public class CommonUtils {
    private static SharedPreferences sp = null;

    private static SharedPreferences spInstance(Context context) {
        if (null == sp) {
            sp = context.getSharedPreferences(Conts.SPKey.SP_KEY, Context.MODE_APPEND);
        }
        return sp;
    }

    public static void setToken(Context context, String token) {

        spInstance(context).edit().putString(Conts.SPKey.SP_TOKEN, token).commit();
    }

    public static String getToken(Context context) {

        return spInstance(context).getString(Conts.SPKey.SP_TOKEN, Conts.SPKey.SP_TOKEN);
    }


    private static LoadingDialog mProgressDialog = null;

    public static void showProgressDialog(Context context) {
//        DPLogUtil.printStackTrace("printStackTrace");
        if (null == mProgressDialog || !mProgressDialog.isShowing()) {
            mProgressDialog = new LoadingDialog(context);
            mProgressDialog.setCancelable(true);
            mProgressDialog.setCanceledOnTouchOutside(true);
            mProgressDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
                @Override
                public void onDismiss(DialogInterface dialog) {
//                    HttpUtil.cancelRequest();
                }
            });
            mProgressDialog.show();
        }
    }

    public static void hideProgressDialog() {
        if (null != mProgressDialog) {
            mProgressDialog.dismiss();
            mProgressDialog = null;
        }
    }

}
